package com.hntxk.cqzd.sysconfig.sms.action;

import com.hntxk.cqzd.common.action.CqzdBaseController;
import com.hntxk.cqzd.sysconfig.sms.entity.SmsTmpl;
import com.hntxk.cqzd.sysconfig.sms.service.SmsTmplManageService;
import com.hntxk.cqzd.sysconfig.sms.service.impl.SmsTmplManageServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.logging.log4j.LogManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletRequest;


/**
 * @Description: 文件管理 <br>
 * @Project: SP <br>
 * @date 2019/6/4 09:35 <br>
 * @author <a href="huangbiquan@hotmail.com">Huang.Biquan</a>
 */
@Api(value="短信模板", tags={"短信模板接口"})
@Controller
@RequestMapping("cqzd/sysconfig/sms")
@Slf4j
public class SmsTmplController extends CqzdBaseController {

    /** 查询页面的path */

    private final static String LIST_JSP_PATH = "cqzd/sysconfig/sms/smstmpl_list";

    private final SmsTmplManageService smsTmplManageService;
    @Autowired
    public SmsTmplController(@Qualifier("smsTmplService") SmsTmplManageService smsTmplManageService) {
        super(smsTmplManageService,LogManager.getLogger(SmsTmplController.class));
        this.smsTmplManageService = smsTmplManageService;
    }


    /**
     *
     * @return 短信模板
     */
    @ApiIgnore
    @GetMapping(value = "/index")
    public String index() {
        return LIST_JSP_PATH;
    }

    /**
     * 查询基础信息
     * @param model
     * @return
     */
    @ApiOperation("查询基础信息")
    @RequestMapping(value = "/queryList",method = {RequestMethod.GET,RequestMethod.POST}, produces= PRODUCE_UTF8_JSON)
    @ResponseBody
    public String queryBasePatient(@ModelAttribute SmsTmpl model) {

        try {
            //设置分页信息
            return toJson(model, smsTmplManageService.query2Json(SmsTmplManageServiceImpl.MAPPER_NAMESPACE + "query", model, true));
        } catch (Exception e) {
            return getError(e);
        }
    }



    /**
     * 添加
     * @param smsTmpl
     * @return
     */
    @ApiOperation("添加")
    @RequestMapping(value = "/insert",method = {RequestMethod.GET,RequestMethod.POST}, produces= PRODUCE_UTF8_JSON)
    @ResponseBody
    public String insertBasePatient(@ModelAttribute SmsTmpl smsTmpl) {
        try {
            smsTmplManageService.insert(smsTmpl);
            return responseOk();
        } catch (Exception e) { return getError(e); }
    }


    /**
     * 修改
     * @param smsTmpl
     * @return
     */
    @ApiOperation("修改")
    @RequestMapping(value = "/update",method = {RequestMethod.GET,RequestMethod.POST}, produces= PRODUCE_UTF8_JSON)
    @ResponseBody
    public String updateBasePatient(@ModelAttribute SmsTmpl smsTmpl) {
        try {
            smsTmplManageService.update(smsTmpl);
            return responseOk();
        } catch (Exception e) { return getError(e); }
    }


    /**
     * 删除短信模板
     * @param request
     * @return
     */
    @Override
    @DeleteMapping(value = "/delete", produces= PRODUCE_UTF8_JSON)
    @ResponseBody
    public String delete(HttpServletRequest request)
    {
        String string=request.getParameter("ids");
        smsTmplManageService.delete(string, false);
        return responseOk();
    }

}
